package com.ncepu.jjoj.judge;

import com.ncepu.jjoj.judge.strategy.DefaultJudgeStrategy;
import com.ncepu.jjoj.judge.strategy.JavaLanguageJudgeStrategy;
import com.ncepu.jjoj.judge.strategy.JudgeContext;
import com.ncepu.jjoj.judge.strategy.JudgeStrategy;
import com.ncepu.jjoj.judge.codesandbox.model.JudgeInfo;
import com.ncepu.jjoj.model.entity.QuestionSubmit;
import org.springframework.stereotype.Service;

/**策略模式，根据不同的编程语言，对结果执行不同的判断策略
 * @author simon_jiang
 * @version 1.0
 */
@Service
public class JudgeManager {
    JudgeInfo doJudge(JudgeContext judgeContext) {
        QuestionSubmit questionSubmit = judgeContext.getQuestionSubmit();
        String language = questionSubmit.getLanguage();
        JudgeStrategy judgeStrategy = new DefaultJudgeStrategy();
        if ("java".equals(language)) {
            judgeStrategy = new JavaLanguageJudgeStrategy();
        }
        return judgeStrategy.doJudge(judgeContext);
    }
}
